#!/bin/bash
#This is a installation script for Kinect2

Kinect_Installation(){
#sed -i 's/ENABLE_CUDA "Enable CUDA support" ON/ENABLE_CUDA "Enable CUDA support" OFF/g' $work_path/libfreenect2/CMakeLists.txt
echo "step1"
cd libfreenect2/depends && ./download_debs_trusty.sh

echo "step2"
sudo apt-get install -y build-essential cmake pkg-config

echo "step3"
sudo apt-add-repository -y ppa:floe/libusb && sudo apt-get update &&  sudo apt-get install -y libusb-1.0-0-dev

echo "step4"
#sh install_ubuntu.sh && sudo dpkg -i libglfw3*_3.0.4-1_*.deb
sudo dpkg -i libglfw3*_3.0.4-1_*.deb
sudo apt-get -f -y install
sudo dpkg -i libglfw3*_3.0.4-1_*.deb

echo "step5"
sudo apt-get install -y libturbojpeg libjpeg-turbo8-dev

echo "step6"
sudo apt-add-repository -y ppa:deb-rob/ros-trusty && sudo apt-get update && sudo apt-get install -y libopenni2-dev

echo "step7"
cd .. && mkdir -p build && cd build && cmake .. && make && sudo make install

echo "step8"
sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/

echo "step9"
sudo cat >> ~/.bashrc<<EOF
export BUILD_KINECT2=true
EOF
echo "step 0.2 kinect done"
}

unzip libfreenect2.zip

work_path=$(dirname $0)
work_path=$(dirname $(readlink -f $0))
Path=$work_path/libfreenect2

if [ ! -d "$Path" ]; then
	echo "No libfreenect2-mast file found !!! "
else
	Kinect_Installation
fi
